# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=fluidsynth
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.6
pkgrel=3
pkgdesc="A real-time software synthesizer based on the SoundFont 2 specifications (mingw-w64)"
arch=('any')
url="http://www.fluidsynth.org/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsndfile"
         "${MINGW_PACKAGE_PREFIX}-portaudio")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-nasm"
             "${MINGW_PACKAGE_PREFIX}-libtool")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-10-ftbfs-bug-690006.all.patch
        0002-1001-revert_abi_break_114.all.patch
        0003-include-blddir.all.patch
        0004-disable-rtkit-bindings-on-w32.all.patch)
sha256sums=('50853391d9ebeda9b4db787efb23f98b1e26b7296dd2bb5d0d96b5bccee2171c'
            '42c1a73052776c530060817702a0245aee1a1bb33be4c329e1bf150959e664ae'
            '31892883cdbf8f5984e1f62906eac49d2b2e9176eb3c049efbcc7ecd47a1be9a'
            '84e23c61efe2a34409cbc2b417988ade926d6881d46efccc92fcc05f2287050d'
            '21cca1fb71459611f422bd71fc58ca4dd0fffcf03cbe86e9e90b5d76025f2363')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-10-ftbfs-bug-690006.all.patch
  patch -p1 -i ${srcdir}/0002-1001-revert_abi_break_114.all.patch
  patch -p1 -i ${srcdir}/0003-include-blddir.all.patch
  patch -p1 -i ${srcdir}/0004-disable-rtkit-bindings-on-w32.all.patch

  ./autogen.sh
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --without-readline \
    --enable-shared \
    --enable-static \
    STRIP=true CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" PTHREAD_LIBS=-lpthread

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
